<?php

/* @version V 1.0
* @date Wed Oct 03 2007
 *
 *  Part of the CEFIRO dynamic web framework project
 *
 *  Copyright (C) 2007  Dyr technologies http://dyrtech.com.ve
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
*
*/

include "basicgraph.php";
include ("jpgraph_gantt.php");

class GanttCe extends basicGraph  {
  public $graph;
  public $name;
  public $data;
  public $height;
  public $width;

	 /**
	 * @brief Constructor por omision y parametrico de la clase
	 *
	 * @param string $__title titulo
	 * @return GantCE La instancia de la clase
	 */

  public function GanttCe($__title = '',$_width = "600px", $_height = "200px")
  {
  	$this->graph= new GanttGraph();
   	$this->graph->title-> Set($__title);
   	$this->graph->title-> SetFont( FF_VERA , FS_BOLD,11);
  	$this->graph->ShowHeaders(GANTT_HYEAR | GANTT_HMONTH | GANTT_HWEEK );
  	$this->graph->scale->UseWeekendBackground(false);
  	
  	$this->width = $_width;
  	$this->height = $_height;
 //	$this->graph->scale->SetDateLocale('es_ES.utf8');
  }

  public function get_name()
  {
	return $this->name;
  }

  public function set_name($_name)
  {
	$this->name=$_name;
  }
  
  public function get_height(){return $this->height;}
  
  public function set_height($_height){
  	$this->height = $_height;
  }
  
  public function get_width(){return $this->width;}
  
  public function set_width($_width){
  	$this->width = $_width;
  }

  public function set_title($_title)
  {
	$this->graph->title->Set($_title);
  }


   	/**
   	 *
   	 *  @brief Asigna los datos de las actividades del gantt
   	 *
	   */

  public function  set_data($_acts_query,$_act_name, $_act_name2 ,$_init_date_name,$_final_date_name)
  {
 	$i=0;
if (!empty($_acts_query)) {
	foreach ($_acts_query as $activity)
		{
			$etiqueta = $activity[$_act_name]." ".$activity[$_act_name2];
			$diagrama = new GanttBar($i,$etiqueta,
			str_replace('/','-',$activity[$_init_date_name]),str_replace('/','-',$activity[$_final_date_name]));

			$diagrama->title-> SetFont( FF_VERA , FS_BOLD,9);

			$this->graph->Add($diagrama);
			$i++;
		}
	 }else{
	  $diagrama = new GanttBar(0,"No existen componentes en el dagrama !",Fecha::hoy(5),Fecha::hoy(5));
		$diagrama->title-> SetFont( FF_VERA , FS_BOLD,9);
		$this->graph->Add($diagrama);
	 }
  }


   	/**
	 * @brief Asigna el GantCE a la variable $smarty para su renderizacion
	 *
	 */
	public function display_gantt(){
	$addr =  ROOT.HOME.'/tmp/gan.png';
	$this->imagen = $this->graph->Stroke($addr);
	global $smarty;
	$smarty->assign('addr', BASE_URL.HOME.'/tmp/gan.png');
	$smarty->assign("width",$this->get_width());
	$smarty->assign("height",$this->get_height());
	$smarty->template_dir = dirname(__FILE__).'/';
	$smarty->assign( $this->name , $smarty->fetch('ganttce.tpl') );
	}

}


?>
